using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using EntLibEC.Cmn;
using EntLibEC.Biz.Report;
using EntLibEC.Biz;

namespace EntLibEC.View.Report
{
	/// <summary>
	/// Summary description for ProductDailyClick.
	/// </summary>
	public partial class ProductDailyClick : PageBase
	{

		protected EntLibEC.View.Cmn.StockProduct ucProduct;
		protected EntLibEC.View.Cmn.Category ucCategory;
		protected EntLibEC.View.Cmn.Manufacturer ucManu ;
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			base.CheckAccess((int)AppEnum.Privilege.OtherReportSearch,true ,null);
			txtDateFrom.Attributes["onclick"]= "javascript:calendar()";
			txtDateTo.Attributes["onclick"]= "javascript:calendar()";

			if ( !Page.IsPostBack )
			{
				ucCategory.BindCategory();				
				txtDateFrom.Text = txtDateTo.Text = DateTime.Now.ToString(AppConst.DateFormat);
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		private bool checkForm()
		{
			if ( !checkDate(txtDateFrom, "Date From") || !checkDate(txtDateTo, "Date To"))
				return false;

			return true;

		}
		private bool checkDate(TextBox txt, string txtName)
		{
			if ( txt.Text.Trim() == "")
			{
				Assert(lblMessage, txtName + " can't be empty", -1);
				return false;
			}
			else
			{
				try
				{
					Convert.ToDateTime(txt.Text.Trim());
				}
				catch
				{
					Assert(lblMessage, txtName + " format error", -1);
					return false;
				}
			}
			return true;

		}

		protected void btnSearch_Click(object sender, System.EventArgs e)
		{
			if ( !checkForm())
				return;

			Hashtable ht = new Hashtable(10);
			ht.Add("DateFrom", txtDateFrom.Text.Trim());
			ht.Add("DateTo", txtDateTo.Text.Trim());
			
			if ( ucProduct.ProductSysNo != AppConst.IntNull)
				ht.Add("ProductSysNo", ucProduct.ProductSysNo);


			if ( ucCategory.C3SysNo != AppConst.IntNull )
				ht.Add("Category", " c3sysno= " + ucCategory.C3SysNo);
			else if ( ucCategory.C2SysNo != AppConst.IntNull )
				ht.Add("Category", " c2sysno= " + ucCategory.C2SysNo);
			else if ( ucCategory.C1SysNo != AppConst.IntNull )
				ht.Add("Category", " c1sysno= " + ucCategory.C1SysNo);

			if(txtProductName.Text.Trim() != AppConst.StringNull)
				ht.Add("ProductName" , txtProductName.Text.Trim());

			if(ucManu.ManuSysNo != AppConst.IntNull)
				ht.Add("Manufactory" , ucManu.ManuSysNo);

			ht.Add("Top", Convert.ToInt32(ddlTop.SelectedItem.Value));


			DataSet ds = ReportManager.GetInstance().GetProductDailyClickDs(ht);

			DataGrid1.DataSource = ds;
			DataGrid1.DataBind();

			int rows = 0;
			if ( Util.HasMoreRow(ds) )
				rows = ds.Tables[0].Rows.Count;
			Assert(lblMessage, rows.ToString() + " record(s)", 1);
		
		}
	}
}
